package init

import (
	utlis2 "api-getway/utlis"
	"flag"
	"fmt"
	"log"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	pb "google.golang.org/grpc/examples/helloworld/helloworld"
)

func init() {
	GrpcInit()
}

func GrpcInit() {

	//连接到指定consul服务器
	consul := utlis2.NewClient("14.103.174.104:8500")
	conf := utlis2.GrpcConf{
		Name:    "user-ser",           //名称
		Tags:    []string{"user-ser"}, //标签
		Post:    50051,                //端口
		Address: "127.0.0.1",          //地址
	}

	//服务注册到consul
	err := consul.RegisterServer(conf)
	if err != nil {
		return
	}

	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	c := pb.NewGreeterClient(conn)
	fmt.Println(c)
}
